#include "btform.h"
#include "ui_btform.h"

BtForm::BtForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BtForm)
{
    ui->setupUi(this);

    //默认都隐藏
    ui->lineBox->hide();

    //设置动画
    _line1Animation = new QPropertyAnimation( ui->line1, "geometry", this);
    _line1Animation->setDuration(1500);
    _line1Animation->setKeyValueAt(0 , QRect(0, 15, 2, 0));
    _line1Animation->setKeyValueAt(0.5 , QRect(0, 0, 2, 15));
    _line1Animation->setKeyValueAt(1 , QRect(0, 15, 2, 0));
    _line1Animation->setLoopCount(-1);
    _line1Animation->start();

    _line2Animation = new QPropertyAnimation( ui->line2, "geometry", this);
    _line2Animation->setDuration(1600);
    _line2Animation->setKeyValueAt(0 , QRect(7, 15, 2, 0));
    _line2Animation->setKeyValueAt(0.5 , QRect(7, 0, 2, 15));
    _line2Animation->setKeyValueAt(1 , QRect(7, 15, 2, 0));
    _line2Animation->setLoopCount(-1);
    _line2Animation->start();

    _line3Animation = new QPropertyAnimation( ui->line3, "geometry", this);
    _line3Animation->setDuration(1700);
    _line3Animation->setKeyValueAt(0 , QRect(14, 15, 2, 0));
    _line3Animation->setKeyValueAt(0.5 , QRect(14, 0, 2, 15));
    _line3Animation->setKeyValueAt(1 , QRect(14, 15, 2, 0));
    _line3Animation->setLoopCount(-1);
    _line3Animation->start();

    _line4Animation = new QPropertyAnimation( ui->line4, "geometry", this);
    _line4Animation->setDuration(1800);
    _line4Animation->setKeyValueAt(0 , QRect(21, 15, 2, 0));
    _line4Animation->setKeyValueAt(0.5 , QRect(21, 0, 2, 15));
    _line4Animation->setKeyValueAt(1 , QRect(21, 15, 2, 0));
    _line4Animation->setLoopCount(-1);
    _line4Animation->start();
}

BtForm::~BtForm()
{
    delete ui;
}

void BtForm::setbtIconAndText(const QString &btIcon, const QString &btText,int pageid)
{
    //设置图片
    ui->btIcon->setPixmap(btIcon);
    //设置文字
    ui->btText->setText(btText);
    //设置页号
    this->_pageid = pageid;
}

int BtForm::Pageid()
{
    return _pageid;
}

void BtForm::clearBackground()
{
    ui->btStyle->setStyleSheet("#btStyle:hover{background-color:#D8D8D8;}");
}

void BtForm::showAnimation(bool isShow)
{
    if(isShow)
    {
        ui->lineBox->show();
    }
    else
    {
        ui->lineBox->hide();
    }
}

void BtForm::mousePressEvent(QMouseEvent *event)
{
    (void)event;
    //1. 切换背景颜色
    ui->btStyle->setStyleSheet("#btStyle{background-color:rgb(30,206,154);}");

    //2. 切换页面: 发送信号 ， 通过musicPlayer槽函数 实现页面切换效果
    emit btClick(this->_pageid);
}
